package com.zxl.register.server.schedule;

import com.zxl.register.server.config.RegisterServerConfig;
import com.zxl.register.server.event.EventProcess;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 检查客服端心跳数据
 */
public class ServerSchedule {


    /**
     * 检查心跳时间是否超时，如果超时，则将instance的状态设置为 下线状态（2）
     */

    public static void checkClientHeartBeat(){
        ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
        long period = RegisterServerConfig.getInstance().getPeriod();
        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                EventProcess.checkHeartBeat();
            }
        },period,period, TimeUnit.MILLISECONDS);
    }

}
